<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" errorPage="/error.jsp" isELIgnored="false" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://atleap.blandware.com/taglib" prefix="atleap" %>
<html:xhtml />

<atleap:constants className="com.blandware.atleap.model.questionnaire.Question" scope="page" var="LINE" />
<atleap:constants className="com.blandware.atleap.model.questionnaire.Question" scope="page" var="MULTILINE" />
<atleap:constants className="com.blandware.atleap.model.questionnaire.Question" scope="page" var="DROPDOWN_LIST" />
<atleap:constants className="com.blandware.atleap.model.questionnaire.Question" scope="page" var="RADIO_BUTTONS" />
<atleap:constants className="com.blandware.atleap.model.questionnaire.Question" scope="page" var="CHECK_BOXES" />
<atleap:constants className="com.blandware.atleap.model.questionnaire.Question" scope="page" var="MULTILIST" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="HTML_TEXT_FIELD_MAX_LENGTH" />
<atleap:constants className="com.blandware.atleap.webapp.util.questionnaire.QuestionnaireModuleWebConstants" var="REGEX_IDENTIFIER_KEY_PREFIX" />
<atleap:javascript formName="questionForm" staticJavascript="false" dynamicJavascript="true" method="validateForm" cdata="false" />
<atleap:content identifier="information" ignore="true" uri="/questionnaire/question/callCreate" />
<atleap:message key="questionnaire.question.errors.title.nothingChecked" var="errorMessage" />
<c:set var="dontNeedCheckBoxes" value="${questionForm.localesMode != 'selected'}" />
<c:set var="hasCheckBoxValidation" value="hasCheckedBox(this, 'toggleAll', &#039;${errorMessage}&#039;)" />
<atleap:form action="questionnaire/question/callCreateTitle" method="POST" onsubmit="var isValidForm = bCancel ? true : (validateForm(this) && ${dontNeedCheckBoxes ? 'true' : hasCheckBoxValidation}); disableButtons(this, isValidForm); return isValidForm;">
    <atleap:messages />
    <table cellpadding="0" cellspacing="0" border="0" class="modificationTable">
        <tr>
            <th>
                <atleap:label property="type" styleClass="label"  key="questionnaire.question.form.type" colon="false" helpTip="true" />
            </th>
            <td>
                <html:select property="type" onchange="var type = this.options[this.selectedIndex].value; var e1 = this.form.elements['validationRegex']; var e2 = this.form.elements['regexFromList']; var disabled = (type != ${LINE} && type != ${MULTILINE}); e1.disabled = disabled; e2.disabled = disabled;">
                    <html:option value="${pageScope.LINE}"><atleap:message key="questionnaire.question.form.type.${pageScope.LINE}" /></html:option>
                    <html:option value="${pageScope.MULTILINE}"><atleap:message key="questionnaire.question.form.type.${pageScope.MULTILINE}" /></html:option>
                    <html:option value="${pageScope.DROPDOWN_LIST}"><atleap:message key="questionnaire.question.form.type.${pageScope.DROPDOWN_LIST}" /></html:option>
                    <html:option value="${pageScope.RADIO_BUTTONS}"><atleap:message key="questionnaire.question.form.type.${pageScope.RADIO_BUTTONS}" /></html:option>
                    <html:option value="${pageScope.CHECK_BOXES}"><atleap:message key="questionnaire.question.form.type.${pageScope.CHECK_BOXES}" /></html:option>
                    <html:option value="${pageScope.MULTILIST}"><atleap:message key="questionnaire.question.form.type.${pageScope.MULTILIST}" /></html:option>
                </html:select>
            </td>
        </tr>
        <tr>
            <th>
                <atleap:label property="required" styleClass="label"  key="questionnaire.question.form.required" colon="false" helpTip="true" />
            </th>
            <td>
                <html:checkbox property="required" />
            </td>
        </tr>
        <tr>
            <th>
                <atleap:label property="validationRegex" styleClass="label"  key="questionnaire.question.form.validationRegex" colon="false" helpTip="true" />
            </th>
            <td>
                <html:text property="validationRegex" maxlength="${pageScope.HTML_TEXT_FIELD_MAX_LENGTH}" styleClass="text" />
                <br />
                <html:select property="regexFromList" onchange="var index = this.selectedIndex; var regex = (index == 0) ? '' : this.options[index].value; var e = this.form.elements['validationRegex']; e.value = regex;">
                    <html:option value="-1">&nbsp;</html:option>
                    <atleap:iterator items="${validationRegexes}" var="entry">
                        <c:set var="value">
                            <c:out value="${entry.value}" escapeXml="true" />
                        </c:set>
                        <html:option value="${value}"><atleap:message key="${pageScope.REGEX_IDENTIFIER_KEY_PREFIX}${entry.key}" /></html:option>
                    </atleap:iterator>
                </html:select>
            </td>
        </tr>
    </table>

    <c:if test="${!dontNeedCheckBoxes}">
        <%-- List of title values for this question --%>
        <tiles:insert definition=".core.contentLocale.selectLocales" flush="false">
            <tiles:put name="listTitleKey" value="questionnaire.question.title.list" direct="true" />
            <tiles:put name="nothingCheckedErrorKey" value="questionnaire.question.errors.title.nothingChecked" direct="true" />
            <tiles:put name="languageKey" value="questionnaire.question.form.language" direct="true" />
            <tiles:put name="checkedBoxProperty" value="titleCheckedBox" direct="true" />
            <tiles:put name="exceptionCheckboxes" value="new Array('required')" direct="true" />
        </tiles:insert>
    </c:if>

    <atleap:iterator items="${questionForm.titleMap}" var="entry">
        <html:hidden property="title(${entry.key})" />
    </atleap:iterator>

    <html:hidden property="localesMode" />
    <html:hidden property="questionnaireId" />

    <atleap:cancel styleClass="button"><atleap:message key="core.commons.buttons.cancel" /></atleap:cancel>
    <atleap:submit styleClass="button"><atleap:message key="core.commons.buttons.next" /></atleap:submit>
</atleap:form>
